<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <link rel="apple-touch-icon" sizes="76x76" href="{_INDEX_STATIC_}/moban/assets/img/apple-icon.png">
    <link rel="icon" type="image/png" href="{_INDEX_STATIC_}/moban/assets/img/favicon.png">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>首页 | {$system_name}</title>
    <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no'
        name='viewport' />
    <link href="{_INDEX_STATIC_}/moban/assets/css/bootstrap.min.css" rel="stylesheet" />
    <link href="{_INDEX_STATIC_}/moban/assets/css/now-ui-kit.css?v=1.1.0" rel="stylesheet" />
    <link href="{_INDEX_STATIC_}/moban/assets/css/font-awesome.min.css" rel="stylesheet" />
</head>

<body class="index-page sidebar-collapse">

    <!-- 引入导航栏 -->
    {include file='public/header'}

    <!-- 内容页 -->
    <div class="container" style="min-height: 490px;">
        <!-- 个人信息 -->
        <div class="row">
            <div class="col-md-12">
                <h3>成果详情 - {$classify_info.name}</h3>
            </div>

        </div>

        <div class="row">
            <div class="col-md-12">
                <button class="btn btn-info" onclick="add('{$classify_table_info.cid}')">添加一条新纪录</button>
                <button class="btn btn-success" onclick="upload_template()">批量上传</button>
                <input type="file" id="file_upload" name="file_upload" style="display: none;"
                    accept="text/csv,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
                <button class="btn btn-success" onclick="download_template('{$classify_info.id}')">模板下载</button>
                <button class="btn btn-success" onclick="achievement_import('{$classify_info.id}')">成果导出</button>
                <button class="btn btn-danger" onclick="back('{$uid}')">返回上一页</button>
            </div>
            <div class="col-md-12">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th style='vertical-align: middle;text-align: center;'>#</th>
                            {volist name="classify_table_info.table_content.names" id="row"}
                            <th style='vertical-align: middle;text-align: center;'>{$row}</th>
                            {/volist}
                            <th style="width:260px;vertical-align: middle;text-align: center;">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {volist name="classify_table_other_data" id="row" key="k"}
                        <!-- 初始化一个变量 -->
                        <!-- {$k=0} -->
                        <tr>
                            <td style='vertical-align: middle;text-align: center;'>{$row.id}</td>
                            {volist name="classify_table_info.table_content.names" id="var"}

                            {if
                            condition="$classify_type_list[$classify_table_info.table_content.selects[$k]-1]['name'] ==
                            '时间'"}
                            <td style='vertical-align: middle;text-align: center;'>
                                {$row[$classify_table_info.table_content.cols[$k]] | date='Y-m-d'} </td>
                            {else /}
                            {if
                            condition="$classify_type_list[$classify_table_info.table_content.selects[$k]-1]['name'] ==
                            '数值'"}
                            <td style='vertical-align: middle;text-align: center;'>
                                {$row[$classify_table_info.table_content.cols[$k]] / 100 | floatval} </td>
                            {else /}
                            <td style='vertical-align: middle;text-align: center;'>
                                {$row[$classify_table_info.table_content.cols[$k]]} </td>
                            {/if}
                            {/if}


                            <!-- $k 自增 -->
                            <!-- {$k++} -->
                            {/volist}
                            <td style='vertical-align: middle;text-align: left;'>
                                <!-- 编辑按钮 -->
                                {if condition="$row.status == 0 or $row.status == 3 or $row.status == 4"}
                                <button class="btn btn-info btn-round" type="button"
                                    onclick="edit('{$row.pid}','{$row.id}')">编辑</button>
                                {else /}
                                <button class="btn btn-default btn-round" type="button" disabled>编辑</button>
                                {/if}

                                <!-- 状态按钮 -->
                                {if condition="$row.status == 0"}
                                <button class="btn btn-primary btn-round" type="button"
                                    onclick="audit('{$row.pid}','{$row.id}')">
                                    {$row.status | achievement_submit_status}
                                </button>
                                {else /}
                                {if condition="$row.status == 4"}
                                <button class="btn btn-success btn-round" type="button">
                                    {$row.status | achievement_submit_status}
                                </button>
                                {else /}
                                <button class="btn btn-round" type="button">
                                    {$row.status | achievement_submit_status}
                                </button>
                                {/if}
                                {/if}

                                <!-- 删除按钮 -->
                                {if condition="$row.status == 0 or $row.status == 3"}
                                <button class="btn btn-danger btn-round" type="button"
                                    onclick="del('{$row.pid}','{$row.id}')">删除</button>
                                {else /}
                                <button class="btn btn-default btn-round" type="button" disabled>删除</button>
                                {/if}
                            </td>
                        </tr>
                        {/volist}
                    </tbody>
                </table>
            </div>
            <!-- 加载分页页面 -->
            {include file='public/page'}

        </div>
    </div>
    <!-- 引入页脚 -->
    {include file='public/footer'}

    <script>

        // 添加一条记录
        function add(cid) {
            redirect_url("{:url('Achievement/add')}?cid=" + cid);
        }

        // 模板下载
        function download_template(cid) {
            $.ajax({
                url: "{:url('Achievement/download_template')}",
                data: {
                    'cid': cid,
                },
                type: "POST",
                dataType: "JSON",
                async: true,
                success: function (res) {
                    // 返回结果处理
                    if (res.code == 0) {
                        redirect_url(res.url);
                        return layer.msg(res.msg, { icon: 1, time: 900 });
                    } else {
                        return layer.msg(res.msg, { icon: 2, time: 900 });
                    }
                }
            });
        }

        // 批量上传
        function upload_template() {
            $('#file_upload').click();
        }

        // 上传
        $('#file_upload').change(function () {
            var files = $('#file_upload').prop('files');
            var data = new FormData();
            data.append('achievement_data', files[0]);
            data.append('cid', "{$cid}");
            var index_load = layer.load(1, {
                shade: [0.3, '#fff'] //0.1透明度的白色背景
            });
            // console.log(data);
            $.ajax({
                url: "{:url('Achievement/upload_template')}",
                data: data,
                type: "POST",
                dataType: "JSON",
                contentType: false,
                processData: false,
                success: function (res) {
                    layer.close(index_load);
                    if (res.code == 0) {
                        return layer.msg(res.msg, { icon: 1, time: 900 }, function () {
                            location.reload();
                        });
                    } else {
                        return layer.msg(res.msg, { icon: 2, time: 900 }, function () {
                            console.log(res.data)
                        });
                    }
                },
                error: function (res) {
                    console.log(res.responseText);
                }
            });

            $('#file_upload').val('');
        });

        // 返回指定的位置
        function back(uid) {
            redirect_url("{:url('Achievement/index')}?uid=" + uid);
        }

        // 删除成果
        function del(pid, id) {

            layer.confirm('是否要删除成果', {
                btn: ['是', '否'] //按钮
            }, function () {
                $.ajax({
                    url: "{:url('Achievement/del')}",
                    data: {
                        'pid': pid,
                        'id': id
                    },
                    type: "POST",
                    dataType: "JSON",
                    success: function (res) {
                        // 返回结果处理
                        if (res.code == 0) {
                            return layer.msg(res.msg, { icon: 1, time: 900 }, function () {
                                location.reload();
                            });
                        } else {
                            return layer.msg(res.msg, { icon: 2, time: 900 });
                        }
                    }
                });
            }, function () { });
        }

        // 编辑成果
        function edit(pid, id) {
            redirect_url("{:url('Achievement/edit')}?pid=" + pid + "&id=" + id);
        }

        // 提交审核
        function audit(pid, id) {

            layer.confirm('是否要提交审核', {
                btn: ['是', '否'] //按钮
            }, function () {
                $.ajax({
                    url: "{:url('Achievement/audit')}",
                    data: {
                        'pid': pid,
                        'id': id
                    },
                    type: "POST",
                    dataType: "JSON",
                    success: function (res) {
                        // 返回结果处理
                        if (res.code == 0) {
                            return layer.msg(res.msg, { icon: 1, time: 900 }, function () {
                                location.reload();
                            });
                        } else {
                            return layer.msg(res.msg, { icon: 2, time: 900 });
                        }
                    }
                });
            }, function () { });

        }

        // 成果导出
        function achievement_import(cid) {
            var url = "{:url('Achievement/import_excel')}";
            var index = layer.open({
                type: 1,
                area: ['300px', '90px'],
                fix: false,
                //不固定
                maxmin: false,
                shade: 0.3,
                title: '请选择导出方式',
                content: 'url',
                btn: ['全部', '已通过', '自定义'],
                // 弹层外区域关闭
                shadeClose: true,
                btn1: function (index, layero) {
                    layer.close(index);
                    var data = {
                        'cid': cid,
                        'status': -1
                    };
                    $.ajax({
                        url: url,
                        data: data,
                        type: "POST",
                        dataType: 'JSON',
                        success: function (res) {
                            if (res.code == 0) {
                                redirect_url(res.url);
                                return layer.msg(res.msg, { icon: 1, time: 900 });
                            } else {
                                return layer.msg(res.msg, { icon: 2, time: 900 });
                            }

                        },
                    });
                },
                btn2: function (index, layero) {
                    layer.close(index);
                    var data = {
                        'cid': cid,
                        'status': 0
                    };
                    $.ajax({
                        url: url,
                        data: data,
                        type: "POST",
                        dataType: 'JSON',
                        success: function (res) {
                            if (res.code == 0) {
                                redirect_url(res.url);
                                return layer.msg(res.msg, { icon: 1, time: 900 });
                            } else {
                                return layer.msg(res.msg, { icon: 2, time: 900 });
                            }

                        },
                    });
                },
                btn3: function (index, layero) {
                    layer.close(index);
                    redirect_url("{:url('Achievement/custom_import')}?cid=" + cid);
                }
            });

        }

        // 重定向
        function redirect_url(url) {
            window.location.href = url;
        }
    </script>

</body>

</html>